#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

struct ListNode {
    int val;
    ListNode* next;
    ListNode(int x) : val(x), next(NULL) {}
};

class Node {
   public:
    int val;
    Node* next;
    Node* random;

    Node(int _val) {
        val = _val;
        next = NULL;
        random = NULL;
    }
};

struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
   public:
    int maxSubArray(vector<int>& nums) {
        int accumulate = 0;
        int max = -100;
        for (int i = 0; i < nums.size(); i++) {
            max = nums[i] > max ? nums[i] : max;
            if (nums[i] + accumulate > 0) {
                max = (max > nums[i] + accumulate) ? max : nums[i] + accumulate;
                accumulate += nums[i];
            } else {
                accumulate = 0;
            }
        }
        return max;
    }
};

int main() {
    cout << "Hello, World!";
    vector<int> tmp;
    tmp.push_back(-2);
    tmp.push_back(1);
    tmp.push_back(-3);
    tmp.push_back(4);
    tmp.push_back(-1);
    tmp.push_back(2);
    tmp.push_back(1);
    tmp.push_back(-5);
    tmp.push_back(4);
    Solution().maxSubArray(tmp);
    return 0;
}
